package com.lzs.Service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lzs.DAO.AreaDAO;
import com.lzs.PO.Area;
import com.lzs.PO.Menu;
import com.lzs.PO.Page;
import com.lzs.PO.User;
import com.lzs.Service.AreaService;

@Service
public class AreaServiceImpl implements AreaService {
 @Autowired
  private AreaDAO areaDAO;
	@Override
	public Page<Area> findAreaPagelist(String keyword, Integer pageSize, Integer pageNum) {

		List<Area> arealist = this.areaDAO.findAreaList(keyword);

		int totalRecord = arealist.size();

		Page<Area> page = new Page<Area>(pageNum, pageSize, totalRecord);

		int startIndex = page.getStartIndex();

		page.setList(areaDAO.findAreaPagelist(keyword, startIndex, pageSize));
		
		return page;
	}
	@Override
	public void queryChildAreas(Area parent, String area_id) {
		
		 List<Area> childareas = this.areaDAO.queryChildAreas(parent.getArea_id());
		 
		 
		 for(Area area: childareas) {
			
			 queryChildAreas(area,area_id);
			 
		 }
		 parent.setChildren(childareas);
	 }
	
	@Override
	public Boolean countAreaById(String area_id) {
		long count = this.areaDAO.countAreaById(area_id);
		return count==0;
	}
	@Override
	public void addArea(Map<String, Object> map) {
             this.areaDAO.addArea(map);		
	}
	@Override
	public Area selectAreaById(String area_id) {
		Area area = this.areaDAO.selectAreaById(area_id);
		return area;
	}
	@Override
	public Area selectFatherAreaById(String father_id) {
	    Area father_area = this.areaDAO.findFatherAreaById(father_id);
	    return father_area;
	}
	@Override
	public void updateArea(Map<String, Object> map) {
		
		this.areaDAO.updateArea(map);
		
	}
	@Override
	public void deleteArea(String area_id) {
      
    	   this.areaDAO.deleteArea(area_id);
    	   
       }
	@Override
	public List<Area> selectChildrenAreaById(String area_id) {
		
		List<Area>areaList = this.areaDAO.selectChildrenAreaById(area_id);
		
		return areaList;
		
	}
	@Override
	public Area findAreaById(String area_id) {
		
		Area area = this.areaDAO.findAreaById(area_id);
		
		return area;
	}
	@Override
	public List<Area> findAreaOfAll() {
		
		List<Area>arealist = this.areaDAO.findAreaOfAll();
		
		return arealist;
	}
	@Override
	public List<Area> findAreaWithCounty() {

        List<Area> countylist = this.areaDAO.findAreaWithCounty();
		return countylist;
	}
	}

		



